home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Networking / MacTCP / MacTCP Developer Tools / 802 LAP / LAP802.a next >
Encoding:
Text File  |  1993-06-15  |  7.1 KB  |  260 lines  |  [TEXT/MPS ]

  1. ;********************************************************************
  2. ;    LAP802.a contains protocol handler routines for IEEE 802.3 LAP.
  3. ;
  4. ;   (c) Copyright 1990-91 by Apple Computer, Inc.  All rights reserved.
  5. ;
  6. ;********************************************************************
  7.  
  8.         TITLE    'LAP802'
  9.         CASE    OBJ
  10.  
  11. ;
  12. ; LAP802.a contains the LAP manager routines for attaching and
  13. ; detaching the protocol handlers for 802.3 protocols
  14. ; It contains Lap manager assembler routines.
  15. ;
  16. ;    1.2    11/29/90    Rajesh    written/modified for IEEE 802.3 LAP
  17. ;        1/18/88        JEM        Initial version
  18. ;
  19.         INCLUDE    'SysEqu.a'
  20.         INCLUDE    'Traps.a'
  21.  
  22. LAP802AttachCode    EQU    21
  23. LAP802DetachCode    EQU    22
  24.  
  25. ;
  26. ; long L802Attach(ProcPtr prot_handler, long ioRefNum, char *protType)
  27. ;
  28. ; return 0 if everything is ok else nonzero
  29. ;
  30. L802Attach    PROC    EXPORT
  31. LAPMgrPtr    EQU        $B18                ; Entry point for LAP Manager
  32. LAPMgrCall    EQU        2                    ; Offset to LAP Manager routines
  33. ; L802Entry    EQU        *                    ; L802 routine entry
  34. ARG1        SET        8
  35. ARG2        SET        ARG1+4
  36. ARG3        SET        ARG2+4
  37.             move.l a4,-(sp)                ; push a4 register
  38.             moveq #LAP802AttachCode,d0    ; move 21 in d0 - attach code
  39.             move.l ARG1(sp),a0            ; put pointer to protocol handler in a0
  40.             move.l ARG2(sp),d2            ; put ioRefNum of driver in d2
  41.             move.l ARG3(sp),a1            ; put the protType pointer in a1
  42.             move.l LAPMgrPtr,a4            ; put pointer to LAP Mgr in a4
  43.             jsr LAPMgrCall(a4)            ; jump to start of LAP Mgr routines
  44.             move.l (sp)+,a4                ; pop a4 register
  45.             rts
  46.             ENDPROC
  47.  
  48. ;
  49. ; long L802Detach(long ioRefNum, char *protType)
  50. ;
  51. ; return 0 if everything is ok else nonzero
  52. ;
  53. L802Detach    PROC    EXPORT
  54. LAPMgrPtr    EQU        $B18                ; Entry point for LAP Manager
  55. LAPMgrCall    EQU        2                    ; Offset to LAP Manager routines
  56. ; L802Entry    EQU        *                    ; L802 routine entry
  57. ARG1        SET        8
  58. ARG2        SET        ARG1+4
  59.             move.l a4,-(sp)                ; push a4 register
  60.             moveq #LAP802DetachCode,d0    ; move 22 in d0 - detach code
  61.             move.l ARG1(sp),d2            ; put ioRefNum of driver in d2
  62.             move.l ARG2(sp),a1            ; put the protType pointer in a1
  63.             move.l LAPMgrPtr,a4            ; put pointer to LAP Mgr in a4
  64.             jsr LAPMgrCall(a4)            ; jump to start of LAP Mgr routines
  65.             move.l (sp)+,a4                ; pop a4 register
  66.             rts
  67.             ENDPROC
  68.  
  69.  
  70. ;
  71. ; rdStruct (the read data structure) definition
  72. ;
  73. ph_rp        EQU        0                ;pointer to "ReadPacket" routine 
  74. ph_rr        EQU        ph_rp+4            ;pointer to "ReadRest" routine
  75. ph_bytesleft EQU ph_rr+4            ;number of bytes left to read
  76. ph_a4        EQU        ph_bytesleft+4    ;a4 save area used by driver */
  77. ph_a0        EQU        ph_a4+4            ;a0 save area used by driver */
  78. ph_a1        EQU        ph_a0+4            ;a1 save area used by driver */
  79. ph_a2        EQU        ph_a1+4            ;a2 save area used by driver */
  80.  
  81. cregs        REG    d2-d3/a2-a5    
  82.  
  83. ;
  84. ; GetLAPPtr returns a pointer to the LAP information structure
  85. ;
  86.  
  87.         PROC
  88.         EXPORT    SetLAPPtr, GetLAPPtr    
  89. SetLAPPtr
  90. ARG1        SET        4                        ;LAP_info struct ptr (char *)
  91.             lea.l    LapPtr(PC),a0
  92.             move.l    ARG1(sp),(a0)
  93.             rts
  94.  
  95. GetLAPPtr
  96.             move.l    LapPtr(PC),d0
  97.             rts
  98.  
  99. LapPtr        dc.l    0                        ;pointer to LAP variable storage
  100.             ENDPROC
  101.  
  102. ;
  103. ; GetA5Ptr returns a pointer to the driver global variables
  104. ;
  105.  
  106. GetA5Ptr    PROC    EXPORT
  107.             move.l    A5Ptr,d0
  108.             rts
  109.  
  110. A5Ptr        dc.l    0                        ;pointer to global variables
  111.             ENDPROC
  112.  
  113. ;
  114. ; OSErr ReadPacket(rds,ptr,cnt)
  115. ; struct rdStruct *rds;
  116. ; char * ptr;
  117. ; int cnt;
  118. ;
  119. ; ReadPacket is called by the link-layer to setup the registers from the
  120. ; read data structure and call the ReadPacket entry point
  121. ;
  122.  
  123. ReadPacket     PROC    EXPORT    
  124.             movem.l cregs, -(sp)    
  125. ARG1        SET    6*4 + 4                    ;&rds (struct rdStruct *)
  126. ARG2        SET    ARG1+4                    ;user buffer ptr (char *)
  127. ARG3        SET    ARG2+4                    ;bytes to read (int)
  128.             move.l ARG1(sp), d2            ;get PH register save block
  129.             move.l d2,a4
  130.             movem.l ph_a0(a4), a0-a2    ;restore a0, a1 & a2
  131.             move.l ph_bytesleft(a4), d1    ;restore D1
  132.             move.l ARG2(sp), a3            ;setup buffer pointer
  133.             move.l ARG3(sp), d3            ;and byte count
  134.             move.l ph_a4(a4),a4
  135.             jsr       (a4)                    ;call read packet
  136.             beq.s  @1                    ;no SCC errors
  137.             move.l #-1,d3                ;indicate error condition
  138.             clr.l  d1                    ;no bytes left to read
  139. @1            move.w d3, d0                ;get return code
  140.             ext.l  d0                    ;convert to long
  141.             move.l ARG1(sp), a4            ;get PH register save block
  142.             movem.l a0-a2, ph_a0(a4)    ;save updated a0, a1 & a2
  143.             move.l d1, ph_bytesleft(a4)    ;save new D1
  144.             movem.l (sp)+, cregs
  145.             rts
  146.             ENDPROC
  147.  
  148.     
  149. ; OSErr ReadRest(rds, ptr, cnt)
  150. ; struct rds *rds;
  151. ; char * ptr;
  152. ; int cnt;
  153. ;
  154. ; ReadRest is called to read in the rest of the packet from the Ethernet
  155. ;   driver. FALSE is returned if the buffer was too small. */
  156.  
  157. ReadRest    PROC    EXPORT
  158.             movem.l cregs, -(sp)    
  159. ARG1        SET    6*4 + 4                    ;&rds (struct rdStruct *)
  160. ARG2        SET    ARG1+4                    ;user buffer ptr (char *)
  161. ARG3        SET    ARG2+4                    ;maximum bytes to read (int)
  162.             move.l ARG1(sp), d2            ;get PH register save block
  163.             move.l d2,a4
  164.             movem.l ph_a0(a4), a0-a2    ;restore a0, a1 & a2
  165.             move.l ph_bytesleft(a4), d1    ;restore D1
  166.             move.l ARG2(sp), a3            ;setup buffer pointer
  167.             move.l ARG3(sp), d3            ;and byte count
  168.             move.l ph_a4(a4),a4
  169.             jsr       2(a4)                ;call read rest
  170.             beq.s  @1                    ;no SCC errors
  171.             move.l #-1,d3                ;indicate error condition
  172.             clr.l  d1                    ;no bytes left to read
  173. @1            lea.l    A4Saved(PC), A0        ;restore A4 for app see Inside Mac II-326 third to the last para.
  174.             move.l    A4, (A0)
  175.             move.w d3, d0                ;get return code
  176.             ext.l  d0                    ;convert to long
  177.             move.l ARG1(sp), a4            ;get PH register save block
  178.             movem.l a0-a2, ph_a0(a4)    ;save updated a0, a1 & a2
  179.             move.l d1, ph_bytesleft(a4)    ;save new D1
  180.             movem.l (sp)+, cregs
  181.             rts
  182.  
  183.         EXPORT    SetUpRDS, SetBuffer, ReadBuffered, Lap802p3_ph    
  184.         IMPORT     Lap802_read_ph
  185.  
  186. ;
  187. ; Ptr SetUpRDS(rds)
  188. ; struct rdStruct *rds
  189. ;
  190. ; SetUpRDS is called from a protocol listener to set-up the read
  191. ; data structure in a form than can be used later by C routines
  192. ; It returns the address of the link header already read-in.
  193. ;
  194. SetUpRDS
  195.             move.l a5, -(sp)    
  196. ARG1        SET    1*4 + 4                        ;&rds (struct rdStruct *)
  197.             move.l ARG1(sp), a5                ;Get RDS pointer
  198.             movem.l a0-a2,ph_a0(a5)         ;save away a0, a1 & a2
  199.             move.l a4,ph_a4(a5) 
  200.             lea.l  ReadPacket,a0
  201.             move.l a0,ph_rp(a5)
  202.             lea.l  ReadRest,a0
  203.             move.l a0,ph_rr(a5)
  204.             ext.l  d1                        ;convert bytes-left to long
  205.             move.l d1,ph_bytesleft(a5)
  206.             move.l a3,d0
  207.             move.l (sp)+, a5
  208.             rts
  209. ;
  210. ; void SetBuffer(buf, len)
  211. ; Ptr buf
  212. ; Int len
  213. ;
  214.  
  215. SetBuffer
  216. ARG1        SET        4
  217. ARG2        SET        ARG1+4
  218.             lea.l    BuffPtr(PC),a0
  219.             move.l    ARG1(sp),(a0)
  220.             lea.l    BuffLen(PC),a0
  221.             move.l    ARG2(sp),(a0)
  222.             rts
  223.         
  224.         
  225. BuffPtr        dc.l    0                        ;pointer to LAP packet buffer
  226. BuffLen        dc.l    0                        ;length of LAP buffer
  227.  
  228. A4Saved        dc.l    0                        ;pointer to apps A4
  229.  
  230. Lap802p3_ph        
  231.             jsr Lap802_read_ph
  232.             move.l    A4Saved(PC), A4
  233.             rts
  234. ;
  235. ; ReadBuffered is called instead of SetUp and ReadRest to immediate begin
  236. ; reading data from the LAP into a fixed LAP buffer.  SetBufPtr must be
  237. ; called during initialization to specify the location and size of the buffer
  238.  
  239. ReadBuffered
  240. ;
  241. ; On Call - A0-a2    setup for AppleTalk
  242. ;
  243. ; Returns:    D0 - Number of bytes in Packet or -1 if LocalTalk error
  244. ;
  245.  
  246.             move.l    BuffPtr(PC),a3        ;setup buffer pointer
  247.             move.l    BuffLen(PC),d3        ;and byte count
  248.             ext.l    d1
  249.             move.l    d1,-(sp)            ;save size of packet
  250.             jsr        2(a4)                ;call ReadRest
  251.             beq.s      @1                    ;no SCC errors
  252. ;            _Debugger
  253.             move.l  #-1,(sp)            ;indicate error condition        
  254. @1            lea.l    A4Saved(PC), A0
  255.             move.l    A4, (A0)
  256.             move.l    (sp)+,d0            ;return number of bytes in packet    
  257.             rts
  258.             ENDPROC
  259.             END
  260.